var win = Ti.UI.currentWindow;

var table = Ti.UI.createTableView();
win.add(table);

var updateTweets = function() {
	var httpClient = Ti.Network.createHTTPClient();
	
	httpClient.onload = function() {
		var resultData = JSON.parse(this.responseText);
		var l = resultData.results.length;
		
		var data = [];
		
		for (var i=0; i < l; i++) {
			var tvr = Ti.UI.createTableViewRow();
			
			tvr.add(Ti.UI.createImageView({
				image: resultData.results[i].profile_image_url,
				width: 50,
				height: 50,
				left: 0
			}));
			
			tvr.add(Ti.UI.createLabel({
				text: resultData.results[i].text,
				left:50
			}));
			
			data.push(tvr);
		}
		
		table.setData(data);
	};
	
	httpClient.open('GET','http://search.twitter.com/search.json?q=gtug+zurich',true);
	httpClient.send();
};

win.addEventListener('open', updateTweets);
win.addEventListener('focus', updateTweets);
